package day08.Test2;

import java.util.LinkedList;
import java.util.Scanner;

public class UglyNumber {
    public static void main(String[] args) {
        System.out.println("求第几个丑数");
        int n = new Scanner(System.in).nextInt();
        long r = f(n);
        System.out.println(r);
    }

    private static long f(int n) {
        LinkedList<Long> list3 = new LinkedList<>();
        LinkedList<Long> list5 = new LinkedList<>();
        LinkedList<Long> list7 = new LinkedList<>();

        list3.add(3L);
        list3.add(5L);
        list3.add(7L);
        long r = 0;

        for(int i = 0; i <= n; i++){
            Long a = list3.getFirst();
            Long b = list3.getFirst();
            Long c = list3.getFirst();
            r = Math.min(a, Math.min(b,c));
            if(r == a) list3.removeFirst();
            if(r == b) list3.removeFirst();
            if(r == c) list3.removeFirst();

            list3.add(r * 3);
            list3.add(r * 5);
            list3.add(r * 7);

        }
        return r;
    }

}
